/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ling
 * Date: 2022-03-28
 * Time: 22:01
 */
public class TestDemo2 {
    public static void main(String[] args) {
        int[] array={1,2,3,4,5};
        int a=sum(array);
        System.out.println(a);
    }
    public static int sum(int[] array){
        int sum=0;
        for (int x:array) {
            sum+=x;
        }
        return sum;
    }
    public static void main6(String[] args) {
       int[] array={1,2,3,4,5};
       double a= avg(array);
        System.out.println(a);
    }
    public static double avg(int[] array) {
        int sum=0;
        for (int x:array) {
            sum+=x;
        }
        return (double) sum/array.length;
    }
    public static void main5(String[] args) {
        int a=add(1,2);
        System.out.println(a);
        double b=add(11.2,11.2,11.2);
        System.out.println(b);
    }
    public static int add(int a,int b){
        return a+b;
    }
    public static double add(double a,double b,double c){
        return a+b+c;
    }
    public static void main4(String[] args) {
        int a=fib(4);
        System.out.println(a);
    }
    public static int fib(int n) {
        if(n==1||n==2)
            return 1;
        else
            return fib(n-1)+fib(n-2);
    }

    public static void main3(String[] args) {
        int n=sum(1234);
        System.out.println(n);
    }
    public static int sum(int n) {
        if(n<10)
            return n;
        else {
            int s=n%10+sum(n/10);
            return s;
        }
    }
    public static void main2(String[] args) {
        disPlay(1234);
    }
    public static void disPlay(int n) {
        if(n<10)
            System.out.println(n);
        else {
            disPlay(n / 10);
            System.out.println(n % 10);
        }
    }

//    public static void main2(String[] args) {
//        int sum=fSum(10);
//        System.out.println(sum);
//    }
//    public static int fSum(int n) {
//       if(n<1)
//           return 0;
//       return fSum(n-1)+f(n);
//    }
//    public static int f(int n) {
//        if(n==1)
//            return 1;
//        else
//            return n*f(n-1);
//    }
}
